import telnetlib

host = "127.0.0.1"
port = 6023

tn = telnetlib.Telnet(host, port)
tn.read_until('>>>')
tn.write("engine.stop()\n")
tn.read_until('>>>')
tn.close()
